_logic = _this select 0;
_name = _this select 1;
_tax = _this select 2;
_ic = _this select 3;
_lc = _this select 4;
_reinforce = _this select 5;
_airport = _this select 6;
_object = _this select 7;
_startSide = _this select 8;

sleep 0.01;


_marker = format ["marker_%1", _logic];
_marker setMarkerSize [0.75, 0.75];
_flag = nearestObject [_logic, "FlagCarrier"];
aiStrategicPoints = aiStrategicPoints + [[_flag, _reinforce,_marker,_ic]];

_marker setMarkerText  format ["%1 Money %2 / IC: %3/ LC: %4",_name,_tax,_ic,_lc];
?(_logic != _object) : _marker setMarkerType "Destroy";

?(_reinforce) : _marker setMarkerType "END";
?(_reinforce) : reinforcePostions = reinforcePostions + [[_flag,_name,_marker,_airport]];
?(_reinforce) : [_flag,_marker,_airport] exec "player\Point_actions.sqs";

?!(local _logic) : goto "end"
? (time > 30) : goto "end"
_flag setflagtexture side2_Flag;

maxZones = maxZones + 1;

_trigger = createTrigger ["EmptyDetector", getpos _logic]
_trigger setTriggerActivation ["Any","PRESENT",true]
_trigger setTriggerArea [150, 150, 0, false ]
~1

#loop
_tlist = list _trigger
? (isnil "_tlist") : _tlist = [];
?(count _tlist > 1) : goto "checkSwitch"
?!(alive _object) : goto "SPdestroyed"	
~10
goto "loop"



#side0loop
~10
_marker setmarkercolor side0_MarkerColor
_tlist = list _trigger
_side1TriggerSeizenr =  side1 countSide _tlist
_side0TriggerSeizenr =  side0 countSide _tlist
?!(alive _object) : goto "SPdestroyed"
?(_side1TriggerSeizenr > 0) : goto "checkSwitch"
goto "side0loop"

#side1loop
~10
_marker setmarkercolor side1_MarkerColor
_tlist = list _trigger
_side0TriggerSeizenr =  side0 countSide _tlist
_side1TriggerSeizenr =  side1 countSide _tlist
?!(alive _object) : goto "SPdestroyed"
?(_side0TriggerSeizenr > _side1TriggerSeizenr) : goto "checkSwitch"
goto "side1loop"



#checkSwitch
_side0TriggerSeizenr =  side0 countSide _tlist
_side1TriggerSeizenr =  side1 countSide _tlist

?(_side0TriggerSeizenr > _side1TriggerSeizenr ) AND (markerColor _marker == side0_MarkerColor) : goto "side0loop";
?(_side1TriggerSeizenr > _side0TriggerSeizenr ) AND (markerColor _marker == side1_MarkerColor) : goto "side1loop";

?(_side0TriggerSeizenr > _side1TriggerSeizenr) AND (_side1TriggerSeizenr < 7) AND !(markerColor _marker == side0_MarkerColor) : goto "switchSide0";
?(_side1TriggerSeizenr > _side0TriggerSeizenr) AND (_side0TriggerSeizenr < 7) AND !(markerColor _marker == side1_MarkerColor) : goto "switchSide1";
goto "loop"


#switchSide0
?(markerColor _marker == side1_MarkerColor) : side1_money_income = side1_money_income - _tax; side1_ic_income = side1_ic_income - _ic; side1zones = side1zones - 1; side1_lc_income = side1_lc_income - _lc;
side0_money_income = side0_money_income + _tax
side0_ic_income = side0_ic_income + _ic
side0_lc_income = side0_lc_income + _lc
side0zones = side0zones + 1

publicVariable "side0zones"
publicVariable "side1zones"

_marker setmarkercolor side0_MarkerColor;
_flag setflagtexture side0_Flag

SPSwitch = true
SPName = _name
SPSide = side0Name

publicVariable "SPname"
publicVariable "SPside"
publicVariable "SPSwitch"
goto "side0loop"


#switchSide1
?(markerColor _marker == side0_MarkerColor) : side0_money_income = side0_money_income - _tax; side0_ic_income = side0_ic_income - _ic; side0zones = side0zones - 1; side0_lc_income = side0_lc_income - _lc;

side1_money_income = side1_money_income + _tax;
side1_ic_income = side1_ic_income + _ic
side1_lc_income = side1_lc_income + _lc
side1zones = side1zones + 1

publicVariable "side0zones"
publicVariable "side1zones"

_marker setmarkercolor side1_MarkerColor;
_flag setflagtexture side1_Flag

SPSwitch = true
SPName = _name
SPSide = side1Name

publicVariable "SPname"
publicVariable "SPside"
publicVariable "SPSwitch"
goto "side1loop"


#SPdestroyed

?(markerColor _marker == side0_MarkerColor) : side0_money_income = side0_money_income - _tax; side0_ic_income = side0_ic_income - _ic; side0zones = side0zones - 1; side0_lc_income = side0_lc_income - _lc;
?(markerColor _marker == side1_MarkerColor) : side1_money_income = side1_money_income - _tax; side1_ic_income = side1_ic_income - _ic; side1zones = side1zones - 1; side1_lc_income = side1_lc_income - _lc;
maxZones = maxZones - 1

SPDestroyed = True
SPname= _name
deletemarker _marker
Publicvariable "SPname"
Publicvariable "SPDestroyed"


#end
Exit